<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>权限列表</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link rel="stylesheet" href="/public/static/css/font.css" />
    <link rel="stylesheet" href="/public/static/css/weadmin.css" />
    <style>
      /* td .layui-table-cell {
			height: 50px;
			line-height: 50px;
		} */
    </style>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
    <div class="weadmin-nav">
      <span class="layui-breadcrumb">
        <a><cite>用户管理</cite></a>
        <a><cite>权限管理</cite></a>
      </span>
      <a
        class="layui-btn layui-btn-sm"
        style="line-height: 1.6em; margin-top: 3px; float: right;"
        href="javascript:location.replace(location.href);"
        title="刷新"
      >
        <i class="layui-icon" style="line-height: 30px;">ဂ</i></a
      >
    </div>
    <div class="weadmin-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 we-search">
          <div class="layui-inline">
            <input
              type="text"
              name="keywords"
              placeholder="请输入权限名"
              autocomplete="off"
              class="layui-input"
            />
          </div>
          <button class="layui-btn" lay-submit="" lay-filter="search">
            <i class="layui-icon">&#xe615;</i>
          </button>
        </form>
      </div>
      <div class="weadmin-block">
        <button
          class="layui-btn"
          onclick="WeAdminShow('添加权限','/admin/users/authlist/add')"
        >
          <i class="layui-icon"></i>添加
        </button>
      </div>
      <table class="layui-table" id="demo" lay-filter="test"></table>
      <div class="page"></div>
    </div>
    <script src="/public/lib/layui/layui.js" charset="utf-8"></script>
    <script>
      layui.extend({
        admin: '{/}/public/static/js/admin',
      })
      layui.use(['jquery', 'admin', 'table', 'form'], function () {
        var table = layui.table,
          $ = layui.jquery,
          admin = layui.admin,
          form = layui.form

        //第一个实例
        const tableIns = table.render({
          elem: '#demo',
          // , height: 100
          url: '/admin/users/authlist/data', //数据接口
          parseData: function (res) {
            //res 即为原始返回的数据
            return {
              code: res.code, //解析接口状态
              msg: res.msg, //解析提示文本
              count: res.data.count, //解析数据长度
              data: res.data.arr, //解析数据列表
            }
          },
          page: true, //开启分页
          limit: 5, //每页大小
          limits: [5], //每页大小选择
          // , size: 'sm'
          cols: [
            [
              //表头
              { field: 'id', title: 'ID', fixed: 'left' },
              { field: 'authname', title: '权限名称' },
              { field: 'authurl', title: '权限路径' },
              { title: '操作', templet: '#operateBtn' },
            ],
          ],
        })

        // 搜索内容
        form.on('submit(search)', function (data) {
          tableIns.reload({
            where: {
              //设定异步数据接口的额外参数，任意设
              keywords: data.field.keywords
              //…
            },
            page: {
              curr: 1, //重新从第 1 页开始
            },
          })

          return false
        })

        /*用户-删除*/
        window.member_del = function (obj, id) {
          layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $.ajax({
              url: '/admin/users/authlist/delete',
              data: { id },
              type: 'POST',
              success: function (res) {
                if (res.code === 1) {
                  layer.msg(res.msg)
                  console.log(res)
                } else {
                  $(obj).parents('tr').remove()
                  layer.msg(res.msg)
                }
              },
            })
          })
        }
      })
    </script>
    <script type="text/html" id="operateBtn">
      <a title="编辑" onclick="WeAdminShow('编辑','/admin/users/authlist/edit/{{d.id}}')" href="javascript:;">
      	<i class="layui-icon">&#xe642;</i>
      </a>
      <a title="删除" onclick="member_del(this,'{{d.id}}')" href="javascript:;">
      	<i class="layui-icon">&#xe640;</i>
      </a>
    </script>
  </body>
</html>
